<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {
	
	public	function __construct()
	{
		parent::__construct();
		//$this->load->helper("url");
		$this->load->model("login_model");
		$this->load->model("log_model");
		date_default_timezone_set('Asia/Ho_Chi_Minh');
	}
	public function index()
	{
		$this->load->view('login/login');		
		//$this->load->view('footer_block');
	}
	
	function login_action(){ 
        $result = $this->login_model->validate($_POST['user'],$_POST['pass']);
        // Now we verify the result        
       	if($result==0){
            // If user did not validate, then show them login page again
			$msg = 'Failed';
        	echo $msg;
			//redirect('adminvtv4');
       	}else{
            // If user did validate, 
            // Send them to members area
            $msg = 'Bạn đã đăng nhập thành công';
            $this->log_model->saveLog(1,null,null,"");
            echo $msg;
        }
	}
	
	function logout(){
		$this->session->sess_destroy();
		redirect('login');
	}
}